package com.helloworld.chat.action;

import com.helloworld.chat.cache.CacheManager;
import com.helloworld.chat.cache.UnReadMessageCache;
import com.helloworld.chat.cache.UserCache;
import com.helloworld.chat.entity.User;
import com.helloworld.chat.service.UserService;
import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

@Controller
@Scope("prototype")
public class ChatAction {
    private int fuid;
    @Autowired
    private UserService userService;
    private String result;

    public String getResult() {
        return result;
    }

    public void setResult(String result) {
        this.result = result;
    }


    public int getFuid() {
        return fuid;
    }

    public void setFuid(int fuid) {
        this.fuid = fuid;
    }

    public void setUserService(UserService userService) {
        this.userService = userService;
    }

    public String beginChat(){
        User me= (User) ServletActionContext.getRequest().getSession().getAttribute("loginUser");
        //UserCache userCache= (UserCache) ServletActionContext.getServletContext().getAttribute("userCache");
        UserCache userCache=CacheManager.getUserCache();
        userCache.changeChating(me.getUid()+"",fuid+"");
        UnReadMessageCache urmCache= CacheManager.getUnReadMessageCache();
        //UnReadMessageCache urmCache= (UnReadMessageCache) ServletActionContext.getServletContext().getAttribute("urmCache");
        //System.out.println("u size"+urmCache.getUnReadMessages(me.getUid()+"",fuid+"").size());;
        result=urmCache.getUnReadMessages_JSON(me.getUid()+"",fuid+"");
        return "beginChat";
	}



}
